## creates figure 1

rm(list=ls())

library(tidyverse)

# figure 1 - question topics by year

issuetopics_allyears <- read.csv('issuetopics_allyears.csv')

allpolicies.df <- issuetopics_allyears %>% 
  group_by(year, topic_6) %>% 
  summarize(nq = n()) %>% 
  ungroup() %>% 
  left_join(issuetopics_allyears %>% 
              group_by(topic_6) %>% 
              summarize(nmax = n())) %>% 
  arrange(nmax) %>% 
  mutate(topic_6 = factor(topic_6, levels = unique(topic_6)))

ggplot(allpolicies.df, 
       aes(x = nq, y = topic_6)) +
  geom_col() +
  facet_grid(~ year) +
  labs(y = 'Policy Domain',
       x = 'Number of Questions') +
  theme_bw() +
  scale_y_discrete(breaks = c('economic', 'foreignpolicy', 'cultural', 
                              'immigration', 'socialwelfare', 'lawenforcement'),
                   labels = c('Economic', 'Foreign Policy', 'Cultural',
                              'Immigration', 'Social Welfare', 'Law Enforcement'))

ggsave('figures/plot_questions_by_year.png', width = 8, height = 4)
